package org.myorg.v5;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

public class FPeople5 implements Serializable {
	public int p_num;
	public FGene5 persons[];

	public FPeople5() {
		p_num = 0;
	}
	
	public FPeople5(int num,int length, int goals_num, int gene_type) {
		p_num = num;
		persons = new FGene5[num];

 		for(int i = 0; i < num; i++) {
			persons[i] = new FGene5(length, goals_num, gene_type);
		}
	}
	
	public FPeople5(int num) {
		p_num = num;
		persons = new FGene5[num];
	}
	
	public FPeople5(FPeople5 people) {
		this.p_num = people.p_num;
		this.persons = new FGene5[people.p_num];
		for ( int i = 0; i < people.p_num; i++){
			this.persons[i] = new FGene5(people.persons[i]);
		}

	}
	
	public void clone(FPeople5 people) {
		this.p_num = people.p_num;
		this.persons = new FGene5[people.p_num];
		for ( int i = 0; i < people.p_num; i++){
			this.persons[i] = new FGene5(people.persons[i]);
		}
	}
	
	public void add(FPeople5 p) {
				
		ArrayList<FGene5> all_p =  new ArrayList<FGene5>(0);
		
		for (int i = 0; i < this.p_num; i++) {
			all_p.add(this.persons[i]);
		}
		
		for (int i = 0; i < p.p_num; i++) {
			all_p.add(p.getPersons()[i]);
		}
		
		this.p_num = this.p_num + p.p_num;

		this.persons = all_p.toArray(new FGene5[all_p.size()]);
	}
	
	public FPeople5[] seg(int num) {
		FPeople5[] ap = new FPeople5[num];
		int size = p_num/num;
		for (int i = 0; i < num ; i++) {
			ap[i] = new FPeople5(size);
			for (int j = 0; j < size; j++) {
				ap[i].persons[j] = new FGene5(persons[i*size + j]);
			}
		}
		return ap;
	}


	public FGene5[] getPersons() {
		return persons;
	}
	
	public FGene5 personAt(int index) {
		return persons[index];
	}
	
	public void putPerson(FGene5 gene, int index) {
		persons[index] = new FGene5(gene);
	}
	
	public void print() {
		for (int i = 0; i < p_num; i++) {
			System.out.print(i + "\t");
			persons[i].print();
		}
	}

}


